<template>
  <div id="app">
    <a-input placeholder="请输入任务" class="my_ipt" v-model="inputValue" />
    <a-button type="primary" @click="addItem()">添加事项</a-button>

    <a-button type="primary" @click="actGetList()" style="margin-left: 15px;">Mock 列表</a-button>

    <a-list bordered :dataSource="staList" class="dt_list">
      <a-list-item slot="renderItem" slot-scope="item">
        <!-- 复选框 -->
        <a-checkbox @change="onCheckboxChange($event)">{{ item.info }}</a-checkbox>
        <!-- 删除链接 -->
        <a slot="actions">删除</a>
      </a-list-item>

      <!-- footer区域 -->
      <div slot="footer" class="footer">
        <!-- 未完成的任务个数 -->
        <span>0条剩余</span>
        <!-- 操作按钮 -->
        <a-button-group>
          <a-button type="primary">全部</a-button>
          <a-button>未完成</a-button>
          <a-button>已完成</a-button>
        </a-button-group>
        <!-- 把已经完成的任务清空 -->
        <a>清除已完成</a>
      </div>
    </a-list>
  </div>
</template>

<script>
import { mapState, mapMutations, mapActions } from 'vuex'

export default {
  name: 'app',
  data() {
    return {
      inputValue: ''
    }
  },
  computed: {
    ...mapState(['staList'])
  },
  methods: {
    onCheckboxChange(e) {
      console.log(e)
    },
    addItem() {
      if (this.inputValue.trim() === '') {
        return this.$message.warning('请输入信息')
      }
      this.mutAddItem({ info: this.inputValue })
      this.inputValue = ''
      this.$message.warning('请输入信息')
    },
    ...mapMutations(['mutAddItem']),
    ...mapActions(['actGetList'])
  },
  created() {
    this.actGetList()
  }
}
</script>

<style scoped>
#app {
  padding: 10px;
}

.my_ipt {
  width: 500px;
  margin-right: 10px;
}

.dt_list {
  width: 500px;
  margin-top: 10px;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
